package core;

import java.util.ArrayList;
import java.util.Hashtable;

public class ProductList {
    
    private static ArrayList<Product> products = new ArrayList<Product>();
    
    private static Hashtable<Integer, Product> productHash = new Hashtable<Integer, Product>();
    
    public static ArrayList<Product> getList() {
        return products;
    }
    
    public static Product getProductByType(int type) {
        if (productHash.get(type) == null) {
            System.out.println("sklkajsdja");
        } 
        return productHash.get(type);
    }       
    
    public static Product[] getAllProduct() {
        Product[] ret = new Product[products.size()];
        return products.toArray(ret);
    }
    
    public static void addProduct(Product product) {                                
        boolean found = false;
        for(int i=0;i<products.size();i++) {
            if(products.get(i).NAME==product.NAME) {
                found = true;
                break;
            }
        }
        if(!found) {
            products.add(product);
        }        
        
        if(!productHash.containsKey(product.NAME)) productHash.put(product.NAME, product);
    }
    
    public static int count() {
        return products.size();
    }
    
}
